﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Ebada.Platform.Model;
using DevExpress.XtraGrid.Columns;
using System.Reflection;
using Ebada.Client;
using DevExpress.XtraGrid.Views.Base;
using Ebada.Client.Platform;
namespace Ebada.Modules.Vehicle
{

    public partial class UCVehiclesDetail : DevExpress.XtraEditors.XtraUserControl {
        private GridViewOperation<VehiclesDetail> gridViewOperation;

        public event SendDataEventHandler<VehiclesDetail> FocusedRowChanged;
        public static bool FirstLoad = false;
        public UCVehiclesDetail() 
        {
            InitializeComponent();
        
            gridViewOperation = new GridViewOperation<VehiclesDetail>(gridControl1, gridView1, barManager1,new frmVehiclesDetailEdit());
            gridViewOperation.CreatingObjectEvent +=gridViewOperation_CreatingObjectEvent;
            gridView1.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(gridViewOperation_FocusedRowChanged);
            gridViewOperation.BeforeAdd += new ObjectOperationEventHandler<VehiclesDetail>(gridViewOperation_BeforeAdd);
            InitData();
            initColumns();
            Init_Org();
        }

        void gridViewOperation_BeforeAdd(object render, ObjectOperationEventArgs<VehiclesDetail> e)
        {
            //int Count=MainHelper.PlatformSqlMap.GetRowCount<VehiclesDetail>("");
            //e.Value.VehicleCode =( Count + 1).ToString();
            //e.Value.RegDate = DateTime.Now;
        }

        void gridViewOperation_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) 
        {
            if (FocusedRowChanged != null)
                FocusedRowChanged(gridView1, gridView1.GetFocusedRow() as VehiclesDetail);
        }
        


       
        /// <summary>
        /// 设置隐藏列
        /// </summary>
        /// 
       public  void initColumns() 
        {
            for (int i = 0; i < gridView1.Columns.Count; i++)
            {
                gridView1.Columns[i].VisibleIndex = -1;
            }
            int m = 0;
            gridView1.Columns["VehicleID"].Caption = "车牌号";
            gridView1.Columns["VehicleID"].VisibleIndex = m++;
            gridView1.Columns["ManufacturerName"].Caption = "制造厂名称";
            gridView1.Columns["ManufacturerName"].VisibleIndex = m++;
            gridView1.Columns["VehicleType"].Caption = "车辆类型";
            gridView1.Columns["VehicleType"].VisibleIndex = m++;
            gridView1.Columns["Brand"].Caption = "车辆品牌";
            gridView1.Columns["Brand"].VisibleIndex = m++;
            gridView1.Columns["VehicleModel"].Caption = "车辆型号";
            gridView1.Columns["VehicleModel"].VisibleIndex = m++;
            gridView1.Columns["ChassisNum"].Caption = "底盘型号";
            gridView1.Columns["ChassisNum"].VisibleIndex = m++;
            gridView1.Columns["Color"].Caption = "车身颜色";
            gridView1.Columns["Color"].VisibleIndex = m++;
            gridView1.Columns["EngineNum"].Caption = "发动机号";
            gridView1.Columns["EngineNum"].VisibleIndex = m++;
            gridView1.Columns["VINNum"].Caption = "车辆识别代号（VIN）或条码";
            gridView1.Columns["VINNum"].VisibleIndex = m++;
            gridView1.Columns["EngineType"].Caption = "发动机型号";
            gridView1.Columns["EngineType"].VisibleIndex = m++;
            gridView1.Columns["FuelType"].Caption = "燃料种类";
            gridView1.Columns["FuelType"].VisibleIndex = m++;
            gridView1.Columns["IsImport"].Caption = "国产或进口";
            gridView1.Columns["IsImport"].VisibleIndex = m++;
            gridView1.Columns["Discharge"].Caption = "排量及功率";
            gridView1.Columns["Discharge"].VisibleIndex = m++;
            gridView1.Columns["SteeringType"].Caption = "转向形式";
            gridView1.Columns["SteeringType"].VisibleIndex = m++;
            gridView1.Columns["WheelBase"].Caption = "轮距（前及后）";
            gridView1.Columns["WheelBase"].VisibleIndex = m++;
            gridView1.Columns["TireNum"].Caption = "轮胎数";
            gridView1.Columns["TireNum"].VisibleIndex = m++;
            gridView1.Columns["TireSize"].Caption = "轮胎规格";
            gridView1.Columns["TireSize"].VisibleIndex = m++;
            gridView1.Columns["PlateSpringNum"].Caption = "钢板弹簧片数";
            gridView1.Columns["PlateSpringNum"].VisibleIndex = m++;
            gridView1.Columns["AxleBase"].Caption = "轴距";
            gridView1.Columns["AxleBase"].VisibleIndex = m++;
            gridView1.Columns["AxleNum"].Caption = "轴数";
            gridView1.Columns["AxleNum"].VisibleIndex = m++;
            gridView1.Columns["OverallSize"].Caption = "外廊尺寸";
            gridView1.Columns["OverallSize"].VisibleIndex = m++;
            gridView1.Columns["InternalSize"].Caption = "货厢内部尺寸";
            gridView1.Columns["InternalSize"].VisibleIndex = m++;
            gridView1.Columns["TotalWeight"].Caption = "总质量";
            gridView1.Columns["TotalWeight"].VisibleIndex = m++;
            gridView1.Columns["CapacityLoadWeight"].Caption = "额定载质量";
            gridView1.Columns["CapacityLoadWeight"].VisibleIndex = m++;
            gridView1.Columns["QualityUtilizationFactor"].Caption = "载质量利用系数";
            gridView1.Columns["QualityUtilizationFactor"].VisibleIndex = m++;
            gridView1.Columns["TowsWeight"].Caption = "准牵引总质量";
            gridView1.Columns["TowsWeight"].VisibleIndex = m++;
            gridView1.Columns["RatingPassengers"].Caption = "额定载客";
            gridView1.Columns["RatingPassengers"].VisibleIndex = m++;
            gridView1.Columns["MaxSemiTrailerWeight"].Caption = "半挂车鞍座最大允许总质量";
            gridView1.Columns["MaxSemiTrailerWeight"].VisibleIndex = m++;
            gridView1.Columns["CabRidesPopulation"].Caption = "驾驶室准乘人数";
            gridView1.Columns["CabRidesPopulation"].VisibleIndex = m++;
            gridView1.Columns["LeaveFactoryDate"].Caption = "车辆出厂日期";
            gridView1.Columns["LeaveFactoryDate"].VisibleIndex = m++;
            gridView1.Columns["DimensionaBarCode"].Caption = "二维条码";
            gridView1.Columns["DimensionaBarCode"].VisibleIndex = m++;
            gridView1.Columns["Remark"].Caption = "备注";
            gridView1.Columns["Remark"].VisibleIndex = m++;

        }

       public void Init_Org()
       {
          
           DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit comboBox = new DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit();
           gridView1.Columns["IsImport"].ColumnEdit = comboBox;
           DataTable temptb = new DataTable();
           temptb.Columns.Add("bol1",typeof(bool));
           temptb.Columns.Add("str1", typeof(string));
           DataRow temprow1 = temptb.NewRow();
           temprow1["bol1"] = true;
           temprow1["str1"] = "进口";
           DataRow temprow2 = temptb.NewRow();
           temprow2["bol1"] = false;
           temprow2["str1"] = "国产";
           temptb.Rows.Add(temprow1);
           temptb.Rows.Add(temprow2);

           comboBox.DataSource = temptb;
           comboBox.DisplayMember = "str1";
           comboBox.ValueMember = "bol1";

           DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit comboBox2 = new DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit();
           gridView1.Columns["VehicleID"].ColumnEdit = comboBox2;
           IList<Vehicles> vehi_list = MainHelper.PlatformSqlMap.GetList<Vehicles>("");
           comboBox2.DataSource = vehi_list;
           comboBox2.DisplayMember = "VehicleNumber";
           comboBox2.ValueMember = "VehicleID";
          
       }
        /// <summary>
        /// 封装了数据操作的对象
        /// </summary>
        [Browsable(false)]
       public GridViewOperation<VehiclesDetail> GridViewOperation
       {
            get { return gridViewOperation; }
            set { gridViewOperation = value; }
        }
        /// <summary>
        /// 新建对象设置Key值
        /// </summary>
        /// <param name="newobj"></param>
        void gridViewOperation_CreatingObjectEvent(VehiclesDetail newobj)
        {
            newobj.VehiclesDetailID = newobj.CreateID();
           
        }

        public void InitData()
        {
            gridViewOperation.RefreshData("");
        }

       
      
       
       

    }
}
